package com.ailesson.video.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ailesson.video.model.reply.ChapterReply;
import com.ailesson.video.model.req.ChapterReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.ailesson.video.service.ChapterService;
import com.ailesson.video.model.req.ChapterQueryReq;
import com.ailesson.common.reply.PageResult;
import com.ailesson.common.reply.R;



/**
 * 课程章节
 *
 * @author mac
 * @email mac@gmail.com
 * @date 2024-10-02 10:30:59
 */
@Tag(name = "课程章节模块")
@RestController
@RequestMapping("/admin/video/chapter")
public class ChapterController {
    @Autowired
    private ChapterService chapterService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @Operation(summary = "列表")
    @Parameter(name = "params", in = ParameterIn.DEFAULT, description = "查询参数")
   // @RequiresPermissions("video:chapter:list")
    public R list(@RequestBody ChapterQueryReq params){
        PageResult page = chapterService.queryPage(params);

        return R.success(page);
    }

    @Operation(summary = "大纲列表")
    @Parameter(name = "courseId", in = ParameterIn.DEFAULT, description = "课程ID")
    @GetMapping("/getNestedTreeList/{courseId}")
    public R getTreeList(@PathVariable Long courseId) {
        List<ChapterReply> list = chapterService.getTreeList(courseId);
        return R.success(list);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @Operation(summary = "获取信息")
    @Parameter(name = "id",in = ParameterIn.PATH, description = "ID")
   // @RequiresPermissions("video:chapter:info")
    public R info(@PathVariable("id") Long id){
		ChapterReply chapter = chapterService.info(id);

         return R.success(chapter);
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    @Operation(summary = "添加")
    @Parameter(name = "teacher",in = ParameterIn.QUERY, description = "添加信息")
    //@RequiresPermissions("video:chapter:save")
    public R add(@RequestBody ChapterReq chapter){
        return R.success(chapterService.add(chapter));
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @Operation(summary = "更新")
    @Parameter(name = "teacher",in = ParameterIn.QUERY, description = "更新信息")
    //@RequiresPermissions("video:chapter:update")
    public R update(@RequestBody ChapterReq chapter){
		chapterService.update(chapter);

        return R.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除")
    @Parameter(name = "ids",in = ParameterIn.QUERY, description = "删除主键ids")
    //@RequiresPermissions("video:chapter:delete")
    public R delete(@RequestBody Long[] ids){
		chapterService.removeByIds(Arrays.asList(ids));

        return R.success();
    }

}
